package com.linchong.concurrency.chapter7;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author:linchong
 * @CreateTime:2019-12-31 14:56
 * @Description:
 */
@Slf4j
public class TicketWindowRunnable implements Runnable {

	private int index = 1;
	private final static int MAX = 500;

	private final Object MONITOR = new Object();

	@Override
	public void run() {
		while (true) {
			synchronized (MONITOR) {
				if (index > MAX) {
					break;
				}
				try {
					Thread.sleep(5);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				log.info("{} 的号码是{}", Thread.currentThread(), (index++));
			}
		}

	}
}
